package com.oedtech.esl.repository.esl;

import com.oedtech.esl.model.esl.EslFirmware;
import com.oedtech.esl.model.esl.EslStatus;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;

import javax.transaction.Transactional;
import java.util.List;

/**
 * @Author QiuLongYu
 * @Date 2019/7/30
 */
@Repository
public interface EslStatusDao extends JpaSpecificationExecutor<EslStatus>,JpaRepository<EslStatus,String> {

    @Modifying
    @Transactional
    @Query(value = "INSERT INTO esl_status (tiny_ip,battery,rssi_value,last_update_time) VALUES(?1,?2,?3,now()) " +
            " ON DUPLICATE KEY UPDATE last_update_time=VALUES(last_update_time),battery=VALUES(battery), " +
            "rssi_value=VALUES(rssi_value)", nativeQuery = true)
    void insertOrUpdate(String tinyIP, String battery, String rssiValue);

    @Transactional
    @Modifying
    @Query(value = "delete from esl_status where tiny_ip in(?1)",nativeQuery = true)
    void deleteByTinyIPs(List<String> tinyIPs);
}
